package com.stu.chart.service.impl;

import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.stu.chart.entity.Staff;
import com.stu.chart.service.StaffService;
import com.stu.chart.mapper.StaffMapper;
import com.stu.chart.service.UserPublishService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 *@author dsj
 */
@Service
public class StaffServiceImpl extends ServiceImpl<StaffMapper, Staff>
    implements StaffService{
    @Autowired
    private UserPublishService userPublishService;

    @Override
    public String getpwdbyname(String name) {
        Staff s=this.baseMapper.getpwdbyname(name);
        if(s!=null) {
            return s.getPassword();
        } else {
            return null;
        }
    }

    @Override
    public Integer getUidbyname(String name) {
        Staff s=this.baseMapper.getpwdbyname(name);
        if(s!=null) {
            return s.getStaffId();
        } else {
            return null;
        }
    }

    @Override
    public String getnamebyid(long id) {
        Staff s=this.baseMapper.getnamebyid(id);
        if(s!=null) {
            return s.getUsername();
        } else {
            return null;
        }
    }

    @Override
    public Staff getUser(String name) {
        return this.baseMapper.getpwdbyname(name);
    }

    @Override
    public List<Staff> searchStaff(String name,Integer age1,String sex,Integer age2) {
        if(StringUtils.isBlank(name)){
          return  userPublishService.recommand(name);
        }
        return this.baseMapper.searchStaff(name,age1,sex,age2);
    }
}




